package com.jyu.apts.dto;

import com.jyu.apts.entity.ItemBatchRecord;
import com.jyu.apts.entity.ItemProcessRecord;
import com.jyu.apts.entity.QRCode;
import com.jyu.apts.entity.QRCodeTemplate;
import com.jyu.apts.entityEnum.QRCodeStatusEnum;
import com.jyu.apts.entityEnum.QRCodeTypeEnum;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class QRCodeDto{
	long id;
	String code;
	Integer type;
	String typeName;
	Integer status;
	String statusName;
	String dataValues;
	UserDto author;
	ItemBatchRecordDto itemBatchRecord;
	QRCodeTemplateDto qrCodeTemplate;
	ItemProcessRecordDto itemProcessRecord;
	public QRCodeDto convert(QRCode qrCode) {
		setId(qrCode.getId());
		setCode(qrCode.getCode());
		setType(qrCode.getType());
		setStatus(qrCode.getStatus());
		setStatusName(QRCodeStatusEnum.values()[qrCode.getStatus()].getName());
		setDataValues(qrCode.getDataValues());
		setTypeName(QRCodeTypeEnum.values()[qrCode.getType()].getName());
		QRCodeTemplate qrCodeTemplate = qrCode.getQrCodeTemplate();
		if(qrCodeTemplate!=null) {
			setQrCodeTemplate(new QRCodeTemplateDto().convert(qrCodeTemplate));
		}
		ItemBatchRecord itemBatchRecord = qrCode.getItemBatchRecord();
		if(itemBatchRecord!=null) {
			setItemBatchRecord(new ItemBatchRecordDto().convert(itemBatchRecord));
		}
		setAuthor(new UserDto().convert(qrCode.getAuthor()));
		ItemProcessRecord itemProcessRecord = qrCode.getItemProcessRecord();
		if(itemProcessRecord!=null) {
			setItemProcessRecord(new ItemProcessRecordDto().convertForQRCode(itemProcessRecord));
		}
		return this;
	}
}
